<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/inc/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章管理 - yhj管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${path}/static/css/public.css" media="all"/>
</head>
<body class="">
<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form">
        <div class="layui-inline">
            <div class="layui-input-inline">
                    <input type="text" name="lxName" id="lxName" class="layui-input type"
                           placeholder="请输入类型名称"/>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="wzName" id="wzName" class="layui-input type"
                       placeholder="请输入文章名称"/>
            </div>
        </div>
        <div class="layui-inline">
            <a class="layui-btn search_btn" data-type="reload" >查询</a>
        </div>
    </form>
</blockquote>
<div class="layui-form" style="margin-top: 1%">
    <div class="layui-form-item">
        <div class="layui-inline">
            <button type="button" class="layui-btn addLink_btn"><i class="layui-icon">&#xe61f;</i> 新增文章</button>
        </div>
    </div>
</div>
<table class="layui-table" id="list" lay-filter="tables"></table>

<script type="text/javascript" src="${path}/static/layui/layui.js"></script>
<script type="text/javascript">
    var path = "${path}";
</script>

<script type="text/javascript">
    layui.use(['form', 'layer', 'laydate', 'table', 'upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            upload = layui.upload,
            table = layui.table;

        //供应链订单查询列表
        var tableIns = table.render({
            elem: '#list',
            url: path + '/article/articleData.do',
            page: true,
            cellMinWidth: 95,
            limit: 20,
            limits: [10, 20, 50, 100],
            height: "full",
            id: "tables",
            cols: [[
                {field: 'id', hide: true},
                {
                    field: 'lxName', title: '类型名称', align: 'center', width: '200'
                },
                {
                    field: 'wzName', title: '文章名称', align: 'center', width: '200'
                },
                {
                    field: 'detail', title: '文章内容', align: 'center', width: '200'
                },
                {
                    field: 'fbTime', title: '创建时间', align: 'center', width: '200',
                    templet: function (obj) {
                        return createTime(obj.fbTime);
                    }

                },
                {
                    field: 'xgTime', title: '修改时间', align: 'center', width: '200',
                    templet: function (obj) {
                        return createTime(obj.xgTime);
                    }
                },
                {
                    title: '操作',
                    width: 300,
                    //fixed: "left",
                    align: "center",
                    merge: "id",
                    templet: function (obj) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>\n' +
                            '    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                    }
                }
            ]]
        });

        //列表操作
        table.on('tool(tables)', function (obj) {
            var data = obj.data;       // 获得当前行数据
            var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的event 参数对应的值）
            if (layEvent === 'edit') { //编辑
                editLink(data);
            } else if (layEvent === 'del') { //删除
                layer.confirm('该操作会删除当前数据所关联的所有数据，是否删除？', {icon: 3, title: '提示信息'}, function (index) {
                    var ajaxReturnData;
                    $.ajax({
                        url: path + '/article/delete.do',
                        type: 'post',
                        dataType:"text",
                        data: {id: data.id},
                        success: function (data) {
                            ajaxReturnData = JSON.parse(data);
                            //console.log(ajaxReturnData);
                            //删除结果
                            if (ajaxReturnData.code == '0') {
                                table.reload('tables');
                                layer.msg('删除成功', {icon: 1});
                            } else {
                                layer.msg('删除失败', {icon: 5});
                            }
                        }
                    });
                    layer.close(index);//向服务器发送删除指令
                });
            }
        });

        //搜索
        $(".search_btn").on("click", function () {
            table.reload("tables", {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    lxName: $("#lxName").val(),
                    wzName: $("#wzName").val(),
                }
            })
        });

        $(document).keydown(function (e) {
            if (e.keyCode === 13) {
                $('.search_btn').click();
            }
        });


        //新增
        $(".addLink_btn").click(function () {
            addLink();
        });
    });



    //新增供应链订单查询
    function addLink(edit) {
        var layer = layui.layer; //有时候不加这段话会全屏弹窗
        var index = layer.open({
            title: "新增",
            type: 2,
            area: ['90%', '90%'],
            content: path + "/article/form.do"
        });
        //layui.layer.full(index);
    }
    function editLink(data) {
        var layer = layui.layer; //有时候不加这段话会全屏弹窗
        var index = layer.open({
            title: "更改",
            type: 2,
            area: ['90%', '90%'],
            content: path + "/article/update.do?id=" + data.id
        });
        //layui.layer.full(index);
    }




    // 获取状态
    function getState(v) {
        var str = "";
        if (v === 1) {
            str = "已保存";
        } else if (v === 2) {
            str = "已生效";
        } else if (v === 3) {
            str = "已下单"
        } else if (v === 4) {
            str = "已完成"
        } else if (v === 5) {
            str = "订单已关闭"
        } else if (v === 6) {
            str = "已下单"
        } else if (v === 7) {
            str = "订单关闭审批中"
        }
        return str;
    }

    // 日期格式化
    function createTime(v) {
        if (v != null) {
            var date = new Date(v);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? '0' + m : m;
            var d = date.getDate();
            d = d < 10 ? ("0" + d) : d;
            var h = date.getHours();
            h = h < 10 ? ("0" + h) : h;
            var M = date.getMinutes();
            M = M < 10 ? ("0" + M) : M;
            var S = date.getSeconds();
            S = S < 10 ? ("0" + S) : S;
            var str = y + "-" + m + "-" + d + " " + h + ":" + M + ":" + S;
        } else {
            var str = "暂无";
        }
        return str;
    }
</script>
</body>
</html>